package utils

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
	"fmt"
)

// 计算sha256
func SHA256(input []byte, key string) (string, error) {
	mac := hmac.New(sha256.New, []byte(key))
	if _, err := mac.Write(input); err != nil {
		return "", fmt.Errorf("unable to hash content %w", err)
	}

	return base64.StdEncoding.EncodeToString(mac.Sum(nil)), nil
}
